<div class="main layui-clear">
    <div class="wrap">
        <div class="content detail">
            <div class="fly-panel detail-box">
                <h1>
                    <?php echo $question['title']; ?>
                </h1>
                <div class="fly-tip fly-detail-hint">
                    <span>
                        <?php if ($question['state']==0) {?>
                            未结贴
                        <?php }else{?>
                            已结贴
                        <?php } ?>
                    </span>
                    <div class="jie-admin-box" data-id="8795">
                    </div>
                    <div class="fly-list-hint">
                        <a href="#comment">
                            <i class="iconfont" title="回答">
                                
                            </i>
                            <?php echo $question['answer_num']; ?>
                        </a>
                        <i class="iconfont" title="人气">
                            
                        </i>
                        <?php echo $question['view_num'] ?>
                    </div>
                </div>
                <div class="detail-about">
                    <a class="jie-user" href="{:U('home/u/index',array('id'=>$question['uid']))}">
                        <img src="__ROOT__/<?php echo $question['headface']; ?>"
                        alt="<?php echo $question['username']; ?>">
                        <cite>
                            <?php echo $question['username']; ?>
                            <em>
                                发布于<?php echo date("Y-m-d h:i:s",$question['create_time']); ?>
                            </em>
                        </cite>
                    </a>
                    <div class="detail-hits" id="LAY_jieAdmin" data-id="8795">
                        <span style="color:#FF7200">
                            悬赏：<?php echo $question['experience']; ?>飞吻
                        </span>
                        <?php if ($iscollection['collection']==1) { ?>
                            <span class="layui-btn layui-btn-mini jie-admin layui-btn-danger" type="collect" data-type="add" id="collection" qid="<?php echo $question['id'] ?>">
                                已收藏
                            </span>
                        <?php }else{ ?>
                            <span class="layui-btn layui-btn-mini jie-admin " type="collect" data-type="add" id="collection" qid="<?php echo $question['id'] ?>">
                                收藏
                            </span>
                        <?php     } ?>
                        
                    </div>
                </div>
                <div class="detail-body photos">
                    <?php echo htmlspecialchars_decode($question['content']); ?>
                </div>
            </div>
            <div class="fly-panel detail-box" style="padding-top: 0;">
                <ul class="jieda photos" id="jieda">
                    <?php if (empty($answers)) { ?>
                        <li class="fly-none">
                            没有任何回答
                        </li>
                    <?php }else{ foreach ($answers as $row) { ?>
                        <li data-id="<?php echo $k; ?>">
                            <a name="item-1490233062225">
                            </a>
                            <div class="detail-about detail-about-reply">
                                <a class="jie-user" href="{:U('home/u/index',array('id'=>$row['uid']))}">
                                    <img src="__ROOT__<?php echo $row['headface']; ?>"
                                    alt="<?php echo $row['username']; ?>" layer-index="8">
                                    <cite>
                                        <i>
                                            <?php echo $row['username']; ?>
                                        </i>
                                    </cite>
                                </a>
                                <div class="detail-hits">
                                    <span>
                                        <?php echo date('Y-m-d H:i:s',$row['create_time']); ?>
                                    </span>
                                </div>
                            </div>
                            <div class="detail-body jieda-body">
                                <?php echo htmlspecialchars_decode($row['content']) ?>
                            </div>
                            <div class="jieda-reply">
                                <span class="jieda-zan <?php foreach ($like as $vla) {
                                    if ($vla['aid']==$row['id']) {
                                        echo 'zanok';
                                    }
                                } ?>" type="zan" qid="<?php echo $question['id'] ?>" aid="<?php echo $row['id'] ?>">
                                    <i class="iconfont icon-zan onlike">
                                    </i>
                                    <em>
                                        <?php echo $row['like_num']; ?>
                                    </em>
                                </span>
                                <span type="reply">
                                    <i class="iconfont icon-svgmoban53">
                                    </i>
                                    回复
                                </span>
                            </div>
                        </li>
                    <?php } } ?>
                </ul>
                <div class="layui-form layui-form-pane">
                    <form action="" method="post">
                        <div class="layui-form-item layui-form-text">
                            <a name="comment">
                            </a>
                            <div class="layui-input-block">
                                <textarea id="L_content" name="content" placeholder="我要回答" class="layui-textarea fly-editor" style="height: 150px;"></textarea>
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <input type="hidden" name="jid" value="8795">
                            <input type="hidden" name="qid" value="<?php echo $question['id']; ?>">
                            <button class="layui-btn" lay-filter="reply" lay-submit="">
                                提交回答
                            </button>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>
    <div class="edge">
        <dl class="fly-panel fly-list-one">
            <dt class="fly-panel-title">
                最近热帖
            </dt>
            <?php foreach ($hotView as $row) { ?>
                <dd>
                    <a href="<?php echo U('home/jie/index',array('id'=>$row['id'])) ?>">
                    <?php echo $row['title']; ?>
                    </a>
                    <span>
                        <i class="iconfont"> 
                        </i>
                        <?php echo $row['view_num']; ?>
                    </span>
                </dd>
            <?php } ?>

        </dl>
        <dl class="fly-panel fly-list-one">
            <dt class="fly-panel-title">
                近期热议
            </dt>
            <?php foreach ($hotQuestion as $row) { ?>
                <dd>
                    <a href="<?php echo U('home/jie/index',array('id'=>$row['id'])) ?>">
                        <?php echo $row['title']; ?>
                    </a>
                    <span>
                        <i class="iconfont">
                            
                        </i>
                        <?php echo $row['answer_num']; ?>
                    </span>
                </dd>
            <?php } ?>
        </dl>
    </div>
</div>
<script type="text/javascript">
    layui.use(['form','jquery','layedit'], function(){
              var form = layui.form()
              ,layer = layui.layer
              $= layui.jquery;
              var layedit = layui.layedit;

          //定义富文本编辑器图片上传接口
        layedit.set({
              uploadImage: {
                url: '{:U("home/add/uploadImage")}' //接口url
                ,type: '' //默认post
              }
            });

        index = layedit.build('L_content'); //建立编辑器

       //回复帖子 监听提交
        form.on('submit(reply)', function(data){
            data.field.content = layedit.getContent(index)
            console.log(data);//打印抓到的数据
            $.ajax({
                url: '{:U('home/jie/reply')}',
                type: 'POST',
                dataType: 'json',
                data: data.field,
            })
            .done(function(respones) {
                        if (respones.error==0) {
                            layer.msg(respones.info, function(){});
                        }else{
                            // layer.msg(respones.info, function(){});
                            // layer.alert(respones.info, {icon: 6},function  () {
                            // location.replace('');
                            layer.alert(respones.info, {icon: 6},function  () {
                            location.reload();
                             });
                        };
            })
            .fail(function() {
                console.log("error");
            })
            
            return false;
        });

        //点赞回复
        $('.jieda-zan').click(function(event) {
            onlike = $(this);
            qid = $(this).attr('qid');
            aid = $(this).attr('aid');
            $.ajax({
                url: '{:U('home/jie/onlike')}',
                type: 'POST',
                dataType: 'json',
                data: {qid: qid,aid: aid},
            })
            .done(function(respones) {
                if (respones.error==0) {
                    em = onlike.children('em').html()
                    em = em-0
                    onlike.removeClass('zanok')
                    onlike.children('em').html(em-1)
                }else if(respones.error==3) {
                    layer.msg(respones.info, function(){});
                }else{
                    em = onlike.children('em').html()
                    em = em-0
                    onlike.addClass('zanok');
                    onlike.children('em').html(em+1)
                };
            })
            .fail(function() {
                console.log("error");
            })
            
        });
        
        //收藏
        $('#collection').click(function(event) {
            qid = $(this).attr('qid');
            $.ajax({
                url: '{:U('home/jie/collection')}',
                type: 'post',
                dataType: 'json',
                data: {qid:qid},
            })
            .done(function(re) {
                if (re.error==1) {
                    $("#collection").html('已收藏');
                    $("#collection").addClass('layui-btn-danger')
                }else{
                    $("#collection").html('收藏');
                    $("#collection").removeClass('layui-btn-danger')
                };
                if (re.error==3) {
                    layer.msg("请登录", function(){});
                };
            })
            .fail(function() {
                console.log("error");
            })
            
        });

        //

    });

   

</script>